/**
 * 版本管理模块，提供版本信息管理相关业务功能
 * 
 * @Date: 2015-6-16
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","msgServ", "ajaxServ", "formServ", "bizProto","btnServ","uploadfiles"],
		function($,datagridServ, msgServ, ajaxServ, formServ, bizProto,btnServ,uploadfiles) {

			'use strict';

			var rootid = 'panel-version',
			
			window_id = 'version-win',
			
			moduCode = 'version'
			
			
				
			var public_method = {				
				
				initEdit:function(){
					private_method.initEdit();
				}
				,
				beforeSubmit:function(){
					var _f = $('#'+window_id + ' .main-form')
					var formData = formServ.getDataObj({
						form : _f
					});
					
					if(formData.id && (formData.id).substring(0,3)=='TMP'){
						//清空id
						$('#'+window_id + ' #id').val('');
						formData.id = null;	
					}
					
					return formData;
				}
			}

			var private_method = {
				initEdit : function(_) {
					
					var _default = {
						bizcode : moduCode,
						bizno   : null,
						rootid  : window_id,
						containerid: 'archive-container'
					}
					
					//当前记录行
					var curData = {}
					
					
					var grid = $('#'+ rootid + ' .dg-list')
					var _data = grid.datagrid('getSelections');
					if(_data && _data.length==1){
						
						curData = _data[0];
						//获取业务id
						_default.bizno=_data[0].id;
					}else{
						//初始化id
						var _date = new Date();
						var _id = 'TMP' +moduCode+ _date.getFullYear()+''+(_date.getMonth()+1)+''+_date.getDate()+'' +_date.getMilliseconds();
						curData.tmpid = _id;
						curData.id = _id;
						curData.platform_id=1;
						curData.platform='android';
						$('#'+window_id + ' .main-form').form('load',curData);
						
						_default.bizno= _id;
					}
					//初始化附件
					uploadfiles.initUpload(_default);
					
					//平台选择事件绑定
					var _platformSelect = $('#'+window_id +' #platform_id')
					$(_platformSelect).combobox({						
						onSelect:function(record){
							var _item = $('#'+window_id +' #platform')
							$(_item).val(record.text)
							$(_platformSelect).val(record.value)
						}					
					})
				}				

			};
			
			return public_method;

		});